//  this library.
import 'package:flutter/material.dart';
import 'package:hktk_app/model/question/sz_info_model.dart';
import 'package:hktk_app/util/event_bus_util.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/sz_util.dart';
import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/question/slider_widget.dart';

/// 设置页面
class QuestionSzWidget extends StatefulWidget {
  const QuestionSzWidget({
    super.key,
  });

  @override
  State<QuestionSzWidget> createState() => _QuestionSzWidgetState();
}

class _QuestionSzWidgetState extends State<QuestionSzWidget> {
  /// 相关数据
  late SzInfoModel _model;

  @override
  void initState() {
    super.initState();

    _model = szUtilComm.szInfo;
  }

  @override
  Widget build(BuildContext context) {

    return Container(
      padding: EdgeInsets.all(30),
      decoration: BoxDecoration(
        color: getColorWhite1(szYjms: _model.yjms),
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(30),
          topRight: Radius.circular(30),
        ),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _switchItems(),
          _fontItem(),
        ],
      ),
    );
  }

  /// 开发集合
  _switchItems() {
    return SizedBox(
      height: 152,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _showSwitchItem("夜间模式", _model.yjms, _onChangedFunY),
          _showSwitchItem("答对自动跳到下一题", _model.zdtz, _onChangedFunZ),
        ],
      ),
    );
  }

  /// 显示单选开关
  _showSwitchItem(String title, bool value, Function(bool value) onChangedFun) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          title,
          style: FontUtil.fontBlack1(20, szYjms: _model.yjms),
        ),
        SizedBox(
          width: 96,
          height: 40,
          child: FittedBox(
            fit: BoxFit.contain,
            child: Switch(
              value: value,
              // 激活时原点颜色
              activeColor: colorWhite1,
              // 激活时横条的颜色
              activeTrackColor: getColorBlue1(szYjms: _model.yjms),
              // 非激活时原点的颜色
              inactiveThumbColor: colorWhite1,
              // 非激活时横条的颜色
              inactiveTrackColor: colorBlack5,
              // 配置分流目标的最小大小。
              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
              onChanged: onChangedFun,
            ),
          ),
        ),
      ],
    );
  }

  /// 夜间模式开关
  _onChangedFunY(bool value) {
    debugPrint("questionSzWidget 组件 -> 你点击了夜间模式的单选开关 ===> $value");
    _model.yjms = value;
    szUtilComm.szInfo.yjms = value;
    eventBus.fire(EventQuestionOnYJMS());
    setState(() {});
  }

  /// 自动跳转开关
  _onChangedFunZ(bool value) {
    debugPrint("questionSzWidget 组件 -> 你点击了自动跳转的单选开关 ===> $value");
    _model.zdtz = value;
    szUtilComm.szInfo.zdtz = value;
    setState(() {});
  }

  /// 字体大小调整
  _fontItem() {
    return SizedBox(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "字体大小",
            style: FontUtil.fontBlack1(20, szYjms: _model.yjms),
          ),
          hiSpace(height: 30),
          _bottomWidget(),
        ],
      ),
    );
  }

  /// 底部显示
  _bottomWidget() {
    return Container(
      height: 110,
      padding: EdgeInsets.symmetric(horizontal: 18),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Text(
            "A",
            style: FontUtil.fontBlack1(28, szYjms: _model.yjms),
          ),
          hiSpace(width: 10),
          Expanded(child: _bottomSlider()),
          hiSpace(width: 10),
          Text(
            "A",
            style: FontUtil.fontBlack1(28, szYjms: _model.yjms),
          ),
        ],
      ),
    );
  }

  /// 滑动组件
  _bottomSlider() {
    // return Container();
    return SliderWidget(
      value: _model.ztdx,
      // value:14,
      onChanged: (data) {

        setState(() {
          _model.ztdx = data;
        });

      },
      min: 15,
      max: 25,
      divisions: 10,
      onChangeEnd: (double value) {

        _model.ztdx = value;
        szUtilComm.szInfo.ztdx = value;
        EventQuestionOnZTDX event=EventQuestionOnZTDX();
        event.size=value;
        eventBus.fire(event);

      },
      szYjms: _model.yjms,
    );
  }
}
